const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const MaterialTag = sequelize.define('MaterialTag', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  materialId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'materials',
      key: 'id'
    }
  },
  tagId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'tags',
      key: 'id'
    }
  }
}, {
  tableName: 'material_tags',
  indexes: [
    {
      fields: ['materialId']
    },
    {
      fields: ['tagId']
    },
    {
      unique: true,
      fields: ['materialId', 'tagId']
    }
  ]
});

module.exports = MaterialTag;